﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ViewModel="clr-namespace:MediaBrowser.Gui.ViewModels"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    mc:Ignorable="d" x:Class="MediaBrowser.Gui.Views.PageMusicView"    
    xmlns:fluidKit="clr-namespace:FluidKit.Controls;assembly=FluidKit" 
    xmlns:julmar="http://www.julmar.com/wpfhelpers"
    xmlns:MediaBrowser_Controls="clr-namespace:MediaBrowser.CustomControls;assembly=MediaBrowser.CustomControls"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
	xmlns:Views="clr-namespace:MediaBrowser.Gui.Views"
    xmlns:EffectsLib="clr-namespace:EffectsLib;assembly=EffectsLib"
    xmlns:Converters="clr-namespace:MediaBrowser.Gui.Converters"
    d:DesignWidth="1024" d:DesignHeight="768"
    >

    <!--<UserControl.DataContext>
        <Binding Mode="OneWay" Path="Musics" Source="{StaticResource Locator}"/>
    </UserControl.DataContext>-->

    <UserControl.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/MediaBrowser.Gui;Component/Themes/PlayerDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <ViewModel:ViewModelLocator x:Key="Locator" d:IsDataSource="True"/>

            <Converters:StringToBitmapConverter x:Key="stringToBitmapConverter" />

            <julmar:BindableCommand x:Key="RsDeleteMusicCommand" Command="{Binding DeleteMusicCommand}"/>

            <Storyboard x:Key="ShowCtrlAdminAlbum" AccelerationRatio="0.5" DecelerationRatio="0.5" >
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminAlbum" 
                                           Storyboard.TargetProperty="(UIElement.Opacity)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminAlbum" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminAlbum" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminAlbum" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminAlbum" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
                <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Grid_Left" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                    <DiscreteBooleanKeyFrame KeyTime="00:00:01" Value="False"/>
                </BooleanAnimationUsingKeyFrames>
                <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Grp_Right" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                    <DiscreteBooleanKeyFrame KeyTime="00:00:01" Value="False"/>
                </BooleanAnimationUsingKeyFrames>
                <DoubleAnimation BeginTime="00:00:00" From="0"  To="-0.5" Duration="00:00:00.25"  
                                             Storyboard.TargetName="Grid_Left" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
                <DoubleAnimation BeginTime="00:00:00" From="0"  To="-0.5" Duration="00:00:00.25"  
                                             Storyboard.TargetName="Grp_Right" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
            </Storyboard>

            <Storyboard x:Key="HideCtrlCtrlAdminAlbum" AccelerationRatio="0.5" DecelerationRatio="0.5" >
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminAlbum" 
                                           Storyboard.TargetProperty="(UIElement.Opacity)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminAlbum" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminAlbum" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminAlbum" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminAlbum" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Grid_Left" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                    <DiscreteBooleanKeyFrame KeyTime="00:00:01" Value="True"/>
                </BooleanAnimationUsingKeyFrames>
                <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Grp_Right" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                    <DiscreteBooleanKeyFrame KeyTime="00:00:01" Value="True"/>
                </BooleanAnimationUsingKeyFrames>
                <DoubleAnimation BeginTime="00:00:00" From="-0.5"  To="-0" Duration="00:00:00.25"  
                                             Storyboard.TargetName="Grid_Left" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
                <DoubleAnimation BeginTime="00:00:00" From="-0.5"  To="-0" Duration="00:00:00.25"  
                                             Storyboard.TargetName="Grp_Right" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
            </Storyboard>

            <LinearGradientBrush x:Key="ReflectionBrush"
                             StartPoint="0,0"
                             EndPoint="0,1">
                <GradientStop Offset="0"
                          Color="#7F000000" />
                <GradientStop Offset=".5"
                          Color="Transparent" />
            </LinearGradientBrush>

            <DataTemplate x:Key="ElementFlowDataTemplate">

                <Grid Height="450" Width="350">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="0.5*" />
                        <RowDefinition Height="0.5*" />
                    </Grid.RowDefinitions>

                    <Border x:Name="ElementVisual"
					Background="{x:Null}"
					Padding="1,1,1,0"
					BorderThickness="1"
					Grid.Row="0" BorderBrush="{DynamicResource BckWindow}">
                        <!--<Image Source="{Binding UrlImage,Converter={StaticResource stringToBitmapConverter}}"
					   Stretch="Fill" />-->
                        <Image Source="{Binding UrlImage}"
					   Stretch="Fill" />
                    </Border>
                    <Rectangle OpacityMask="{DynamicResource ReflectionBrush}"
                           Grid.Row="1"
                           Height="{Binding ActualHeight, ElementName=ElementVisual}">
                        <Rectangle.Fill>
                            <VisualBrush Visual="{Binding ElementName=ElementVisual}">
                                <VisualBrush.RelativeTransform>
                                    <ScaleTransform ScaleX="1"
                                                ScaleY="-1"
                                                CenterX="0.5"
                                                CenterY="0.5" />
                                </VisualBrush.RelativeTransform>
                            </VisualBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                </Grid>
            </DataTemplate>
        </ResourceDictionary>

    </UserControl.Resources>

    <UserControl.Triggers>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="btAdd">
            <BeginStoryboard Storyboard="{StaticResource ShowCtrlAdminAlbum}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="btUp">
            <BeginStoryboard Storyboard="{StaticResource ShowCtrlAdminAlbum}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="Views:UserCtrlAdminAlbum.OnClose" SourceName="UserCtrlAdminAlbum">
            <BeginStoryboard Storyboard="{StaticResource HideCtrlCtrlAdminAlbum}"/>
        </EventTrigger>
    </UserControl.Triggers>


    <Grid DataContext="{Binding Musics, Mode=OneWay, Source={StaticResource Locator}}">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="240" />
        </Grid.ColumnDefinitions>

        <!-- LEFT fluidKit:ElementFlow  -->
        <Grid Grid.Column="0" x:Name="Grid_Left">

            <Grid.Effect>
                <EffectsLib:BrightContrastEffect/>
            </Grid.Effect>

            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Grid Grid.Row="0">

                <fluidKit:ElementFlow x:Name="elementFlow"
							  ItemTemplate="{DynamicResource ElementFlowDataTemplate}"
                              TiltAngle="{Binding Value, ElementName=tiltAngleSlider}"
							  ItemGap="{Binding Value, ElementName=itemGapSlider}"
                              ItemsSource="{Binding Medias}"	
                              FrontItemGap="{Binding Value, ElementName=frontItemGapSlider}"
							  PopoutDistance="{Binding Value, ElementName=popoutDistanceSlider}" SelectedIndex="{Binding SelectedIndex}" Margin="0" HasReflection="True" ElementHeight="450" ElementWidth="350">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Loaded">
                            <julmar:InvokeCommand Command="{Binding LoadedCommand, Mode=Default}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                    <fluidKit:ElementFlow.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#33181818"/>
                            <GradientStop Color="#337A7A7A" Offset="0.5"/>
                            <GradientStop Color="#CC1A1A1A" Offset="1"/>
                        </LinearGradientBrush>
                    </fluidKit:ElementFlow.Background>
                    <fluidKit:ElementFlow.Layout>
                        <fluidKit:Carousel />
                    </fluidKit:ElementFlow.Layout>
                    <fluidKit:ElementFlow.Camera>
                        <PerspectiveCamera
								   Position="0,3,6"
								   LookDirection="-0.000588351267544177,-0.388847992723322,-0.921301737976126" NearPlaneDistance="0.1" FieldOfView="40" >
                            <PerspectiveCamera.Transform>
                                <Transform3DGroup>
                                    <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                                    <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                                    <RotateTransform3D d:EulerAngles="15,0,-0.026858974489393">
                                        <RotateTransform3D.Rotation>
                                            <AxisAngleRotation3D Angle="15" Axis="1,0,-0.002"/>
                                        </RotateTransform3D.Rotation>
                                    </RotateTransform3D>
                                    <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                                    <TranslateTransform3D OffsetZ="0" OffsetY="-0.7"/>
                                </Transform3DGroup>
                            </PerspectiveCamera.Transform>
                        </PerspectiveCamera>
                    </fluidKit:ElementFlow.Camera>
                </fluidKit:ElementFlow>

                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="1,0,0,0" >
                    <MediaBrowser_Controls:ImageButton x:Name="btAdd" Command="{Binding PrepareAddAlbumCommand}" Source="/MediaBrowser.Gui;Component/Images/cd_add.png" Height="16" Margin="0,0,5,0" ToolTip="Ajouter un Album" Width="16"/>
                    <MediaBrowser_Controls:ImageButton x:Name="btUp" Command="{Binding PrepareUpdateAlbumCommand}" Source="/MediaBrowser.Gui;Component/Images/cd_edit.png" Height="16" Margin="0,0,5,0" ToolTip="Modifier un Album" Width="16"/>
                    <MediaBrowser_Controls:ImageButton Command="{Binding DeleteAlbumCommand}" Source="/MediaBrowser.Gui;Component/Images/cd_delete.png" Height="16" Margin="0,0,1,0" ToolTip="Supprimer un Album" Width="16"/>
                </StackPanel>

            </Grid>

            <StackPanel Orientation="Vertical"
					Grid.Row="1"
					Margin="5,10,5,5">
                <Label Content="Angle d'inclinaison" />
                <Slider x:Name="tiltAngleSlider"
					Minimum="0"
					Maximum="90" Margin="0,1,0,0" />
                <Label Content="Ecartement" Margin="0,3,0,0" />
                <Slider x:Name="itemGapSlider"
					Minimum="0.25"
					Maximum="5"
					Value="2.5" Margin="0,1,0,0" />
                <Label Content="Ecart arrière" Margin="0,3,0,0" />
                <Slider x:Name="frontItemGapSlider"
            	Minimum="0"
            	Maximum="4.0" Margin="0,1,0,0" Value="2.3" />
                <Label Content="Ecart avant" Margin="0,3,0,0" />
                <Slider x:Name="popoutDistanceSlider"
            	Minimum="-2.5"
            	Maximum="2.5"
            	Value="2.3" Margin="0,1,0,0" />
            </StackPanel>

        </Grid>

        <!-- RIGHT -->
        <GroupBox  Grid.Column="1" Margin="5,0,0,0" 
                  HorizontalContentAlignment="Stretch"
                  VerticalContentAlignment="Stretch"
                  Height="Auto" x:Name="Grp_Right">
            <GroupBox.Header>
                <Label Foreground="WhiteSmoke" 
				  		FontSize="9" 
						FontWeight="Bold" Content="Liste des titres"/>
            </GroupBox.Header>

            <GroupBox.Effect>
                <EffectsLib:BrightContrastEffect/>
            </GroupBox.Effect>

            <Grid>

                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>


                <ListBox Name="lMedias" SelectionMode="Extended" ItemsSource="{Binding MediaItems, Mode=Default}"
                         Grid.Row="0" IsSynchronizedWithCurrentItem="True"  Background="{x:Null}"
                         HorizontalContentAlignment="Stretch" Margin="0,4,0,0" AllowDrop="True">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Background="{x:Null}" Text="{Binding Name}" ToolTip="{Binding Name}" Width="199"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                    <julmar:EventCommander.Mappings>
                        <julmar:CommandEvent Command="{Binding DropMusicCommand}" Event="Drop" CommandParameter="{Binding}" />
                    </julmar:EventCommander.Mappings>
                    <ListBox.InputBindings>
                        <KeyBinding Key="Delete" Command="{StaticResource RsDeleteMusicCommand}" />
                    </ListBox.InputBindings>
                </ListBox>

                <Border Grid.Row="1" Margin="1,0,1,2" CornerRadius="1,1,2,2">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#B24B5059" Offset="0"/>
                            <GradientStop Color="#CC838C9B" Offset="0.985"/>
                        </LinearGradientBrush>
                    </Border.Background>

                    <Grid Margin="10,5" Height="60" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="85"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <StackPanel Orientation="Horizontal" Grid.Column="0" >
                            <Button Style="{StaticResource smartButton}" Content="{StaticResource playSign}" Command="{Binding PlayMusicCommand}" Height="24" Width="24"/>
                            <Button x:Name="button" Style="{StaticResource smartButton}" Content="{StaticResource pauseSign}" Command="{Binding PauseMusicCommand}"  Height="24" Width="24" Margin="5,0,0,0"/>
                            <Button Style="{StaticResource smartButton}" Content="{StaticResource stopSign}" Command="{Binding StopMusicCommand}" Height="24" Width="24" Margin="5,0,0,0"/>
                        </StackPanel>

                        <StackPanel Orientation="Vertical" Grid.Column="1" Margin="10,0,0,0" VerticalAlignment="Bottom">
                            <Slider Template="{DynamicResource TrackSlider}" IsMoveToPointEnabled="True"
                                    Maximum="{Binding TotalDuration}" Value="{Binding CurrentPosition, Mode=TwoWay}"/>
                            <Slider Maximum="1" LargeChange="0.5" Value="{Binding Volume, ElementName=mediaElement, Mode=TwoWay}"  Template="{DynamicResource VolumeSlider}" Width="80" Height="16" Margin="0,4,0,0" IsMoveToPointEnabled="True" />
                            <TextBlock x:Name="ProgressDisplay" Text="{Binding CurrentProgress}" Foreground="#FFFAF7F7"/>
                            <TextBlock Text="{Binding StatusPlayer}" Foreground="#FFEE0F0F" FontWeight="Bold"/>
                            <MediaElement x:Name="mediaElement" d:IsHidden="True" LoadedBehavior="Stop"  Visibility="Collapsed" Source="{Binding CurrentMediaItem.UrlContent}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="MediaOpened">
                                        <julmar:InvokeCommand Command="{Binding MediaOpenedCommand, Mode=Default}" CommandParameter="{Binding ElementName=mediaElement, Mode=OneWay}"/>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                                <julmar:EventCommander.Mappings>
                                    <julmar:CommandEvent Command="{Binding MediaFailedCommand}" Event="MediaFailed" CommandParameter="{Binding}" />
                                </julmar:EventCommander.Mappings>
                            </MediaElement>
                        </StackPanel>
                    </Grid>
                </Border>
            </Grid>

        </GroupBox>

        <!-- ADMIN ALBUM -->
        <Views:UserCtrlAdminAlbum x:Name="UserCtrlAdminAlbum" Width="500" Height="350" Grid.ColumnSpan="3" Grid.RowSpan="3" RenderTransformOrigin="0.5,0.5" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
            <Views:UserCtrlAdminAlbum.RenderTransform>
                <TransformGroup>
                    <ScaleTransform ScaleX="0" ScaleY="0"/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Views:UserCtrlAdminAlbum.RenderTransform>
        </Views:UserCtrlAdminAlbum>


    </Grid>
</UserControl>
